home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / csvlogging.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  102 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import logging
  5. import gzip
  6. import string
  7. from time import strftime
  8. from traceback import print_exception, format_exception
  9. from cStringIO import StringIO
  10. COMMA = '#comma#'
  11. LINE = '#line#'
  12.  
  13. def csv_escape(s):
  14.     return s.replace(',', COMMA).replace('\n', LINE)
  15.  
  16. CSV_HEADERS = 'Time, Log Level, Level Name, Log Name, Message,Pathname, Filename, Module, Function Name, Line No., Timestamp, Thread Count, Thread Name, Thread No., Process No.\n'
  17.  
  18. class CSVFormatter(logging.Formatter):
  19.     _fmt = '%(asctime)s,%(levelno)s,%(levelname)s,%(name)s,%(message)s,%(pathname)s,%(filename)s,%(module)s,%(funcName)s,%(lineno)d,%(created)f,%(threadCount)d,%(threadName)s,%(thread)d,%(process)d'
  20.     
  21.     def __init__(self, fmt = None, datefmt = None):
  22.         logging.Formatter.__init__(self, fmt, datefmt)
  23.         self._fmt = CSVFormatter._fmt
  24.         self._asctime = self._fmt.find('%(asctime)') >= 0
  25.  
  26.     
  27.     def formatTime(self, record, datefmt = None):
  28.         ct = self.converter(record.created)
  29.         if datefmt:
  30.             s = strftime(datefmt, ct)
  31.         else:
  32.             t = strftime('%Y-%m-%d %H:%M:%S', ct)
  33.             s = '%s.%03d' % (t, record.msecs)
  34.         return s
  35.  
  36.     
  37.     def formatException(self, ei):
  38.         s = format_exception(*ei)
  39.         if s.endswith('\n'):
  40.             s = s[:-1]
  41.         
  42.         return s
  43.  
  44.     
  45.     def format(self, record):
  46.         record.message = ''.join(('"', record.getMessage().replace('"', '""'), '"'))
  47.         if self._asctime:
  48.             record.asctime = self.formatTime(record, self.datefmt)
  49.         
  50.         s = self._fmt % record.__dict__
  51.         if record.exc_info:
  52.             if not record.exc_text:
  53.                 record.exc_text = csv_escape(self.formatException(record.exc_info))
  54.             
  55.         
  56.         if record.exc_text:
  57.             if not s.endswith(','):
  58.                 s = s + ','
  59.             
  60.             s = ''.join((s, record.exc_text))
  61.         
  62.         return s
  63.  
  64.  
  65.  
  66. class gzipFileHandler(logging.StreamHandler):
  67.     
  68.     def __init__(self, t, filename = None):
  69.         if not filename:
  70.             filename = 'digsby-' + t + '.log.csv.gz'
  71.         
  72.         f = open('logs/digsby-' + t + '.log.csv.gz', 'wb')
  73.         self.gzfileobj = gzip.GzipFile(filename, fileobj = f)
  74.         self.gzfileobj.write('Time, Log Level, Level Name, Log Name, Message,Pathname, Filename, Module, Function Name, Line No., Timestamp, Thread No., Thread Name, Process No.\n')
  75.         logging.StreamHandler.__init__(self, self.gzfileobj)
  76.  
  77.     
  78.     def close(self):
  79.         logging.StreamHandler.close(self)
  80.         self.gzfileobj.close()
  81.  
  82.  
  83.  
  84. class CloseFileHandler(logging.StreamHandler):
  85.     
  86.     def __init__(self, openfile, level = None, formatter = None):
  87.         self.fileobj = openfile
  88.         logging.StreamHandler.__init__(self, self.fileobj)
  89.         if level is not None:
  90.             self.setLevel(level)
  91.         
  92.         if formatter is not None:
  93.             self.setFormatter(formatter)
  94.         
  95.  
  96.     
  97.     def close(self):
  98.         logging.StreamHandler.close(self)
  99.         self.fileobj.close()
  100.  
  101.  
  102.